package com.muchenxinxi.androidbaseapp.utils;

import android.widget.EditText;
import android.widget.TextView;

/**
 * ┏--------------------
 * │        /) /)
 * │     ฅ(• ﻌ •)ฅ
 * │  Created by HaoKing on 2016/12/4.
 * │  www.muchenxinxi.com
 * │  www.nextdever.com
 * │  QQ:773693552
 * │  QQ群: Geek Chat 344386592
 * ┗--------------------
 */

public class StringUtils {

    public static boolean isEmpty(EditText v) {
        if (v == null)
            return true;
        else
            return isEmpty(v.getText().toString().trim());
    }

    public static boolean isEmpty(TextView v) {
        if (v == null)
            return true;
        else
            return isEmpty(v.getText().toString().trim());
    }

    public static boolean isEmpty(String s) {
        if (s == null)
            return true;
        else
            return s.isEmpty();
    }

    public static boolean isNotEmpty(EditText v) {
        return !isEmpty(v);
    }

    public static boolean isNotEmpty(TextView v) {
        return !isEmpty(v);
    }

    public static boolean isNotEmpty(String s) {
        return !isEmpty(s);
    }

    public static String getString(EditText v) {
        if (null == v) return "";
        return v.getText().toString().trim();
    }

    public static String getString(TextView v) {
        if (null == v) return "";
        return v.getText().toString().trim();
    }

    public static String getString(EditText v, String defaultString) {
        return getString(getString(v), defaultString);
    }

    public static String getString(TextView v, String defaultString) {
        return getString(getString(v), defaultString);
    }

    public static String getString(String s, String defaultString) {
        if (isEmpty(s))
            return defaultString;
        return s;
    }

    public static String formatMoney(float money) {
        return String.format("%1$.2f", money);
    }

}
